package galnaat.szofttech;

import galnaat.szofttech.map.Fieldtype;

import java.util.ArrayList;

public class MyArray {
	public static final int sizeX = mappage.sizeX;
	public static final int sizeY = mappage.sizeY;

	ArrayList<ArrayList> mb = new ArrayList<ArrayList>();
    
    private void rawAdd(ArrayList<ArrayList> where, int i, Fieldtype what) {
		ArrayList<Fieldtype> ms = where.get(i);
		ms.add(what);
	}
    
    private void rawSet(ArrayList<ArrayList> where, int i, int e, Fieldtype what) {
		ArrayList<Fieldtype> ms = where.get(i);
		ms.set(e,what);
	}
    
	public MyArray() {
		for (int x = 0; x<mappage.sizeX; x++) {
			boolean b = mb.add(new ArrayList<Fieldtype>());
			if (b) {
				for (int y = 0; y<mappage.sizeY; y++) {
					rawAdd(mb,x,Fieldtype._);
				}
			}
        }
	}
	
	public void set(int x, int y, Fieldtype f) {
		if (x<sizeX && y<sizeY && x>=0 && y>=0) 
			rawSet(mb,x,y,f);
	}
	
	public Fieldtype get(int x, int y) {
		//System.out.println(x*100 + y);
		if (x<sizeX && y<sizeY && x>=0 && y>=0) {
			ArrayList<Fieldtype> ms = mb.get(x);
			return (Fieldtype)ms.get(y);
		}
		else return Fieldtype.i;
	}
}
